<template>
	<view>
		<template v-if="list.length > 0">
			<!-- 图文列表 -->
			<block v-for="(item, index1) in list" :key="index1">
				<indexList :item="item" :index="index1"></indexList>
			</block>
			<loadMore :loadtext="loadtext"></loadMore>
		</template>
		<template v-else-if="issearch && list.length < 1">
			<!-- 无内容 -->
			<noThing></noThing>
		</template>
	</view>
</template>

<script>
	import indexList from '../../components/index/index-list.vue';
	import noThing from '../../components/common/no-thing.vue';
	import loadMore from '../../components/common/load-more.vue';
	
	export default {
		components:{
			indexList,
			loadMore,
			noThing
		},
		data() {
			return {
				issearch: false,
				loadtext: "上拉加载更多",
				list: [],
				searchtext:""
			}
		},
		//监听原生标题导航按钮点击事件
		onNavigationBarButtonTap(e) {
			// console.log(JSON.stringify(e));
			if (e.index == 0) {
				uni.navigateBack({delta:1});
			}
		},
		//监听搜索框文本变化
		onNavigationBarSearchInputChanged(e) {
			console.log("监听搜索框文本变化",JSON.stringify(e));
			this.searchtext = e.text;
		},
		//监听搜索按钮事件
		onNavigationBarSearchInputConfirmed(e) {
			console.log("监听搜索按钮事件",JSON.stringify(e));
			if (e.text) {
				this.getdata();
			}
		},
		//监听页面触底事件
		onReachBottom() {
			this.loadmore();
		},
		//监听下拉刷新
		onPullDownRefresh() {
			this.getdata();
			uni.stopPullDownRefresh();
		},
		methods: {
			//搜索事件
			getdata() {
				uni.showLoading();
				setTimeout(()=>{
					//请求服务器 post请求 关键字
					let arr = [{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							isguanzhu: false,
							title: "我是标题",
							type: "img", //img:图文 video: 视频
							titlepic: "../../static/demo/datapic/11.jpg",
							infoNum: {
								index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
								dingNum: 11,
								caiNum: 12,
							},
							commentNum: 12,
							shareNum: 123
						},
						{
							userpic: "../../static/demo/userpic/1.jpg",
							username: "昵称",
							isguanzhu: true,
							title: "我是标题",
							type: "video", //img:图文 video: 视频
							titlepic: "../../static/demo/datapic/11.jpg",
							playNum: "20w",
							long: "2:47",
							infoNum: {
								index: 2, //0 - 没有操作, 1 - 顶, 2 - 踩
								dingNum: 1,
								caiNum: 14,
							},
							commentNum: 12,
							shareNum: 123
						}
					];
					this.list = arr;
					uni.hideLoading();
				}, 1000);
				
			},
			// 上拉加载
			loadmore(){
				if(this.loadtext != "上拉加载更多") {return;}
				this.loadtext = "加载中";
				setTimeout(()=>{
					//获取完成
					let obj = {
								userpic: "../../static/demo/userpic/2.jpg",
								username: "昵称",
								isguanzhu: false,
								title: "我是标题",
								type: "img", //img:图文 video: 视频
								titlepic: "../../static/demo/datapic/12.jpg",
								infoNum: {
									index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
									dingNum: 11,
									caiNum: 12,
								},
								commentNum: 12,
								shareNum: 123
							};
					this.list.push(obj);
					this.loadtext = "上拉加载更多";
				},1000)
				// this.newlist[index].loadtext = "上拉加载更多";
				// this.newlist[index].loadtext = "加载中";
				// this.newlist[index].loadtext = "没有更多数据了";
			},
		}
	}
</script>

<style>

</style>
